package com.butuh.uang.tuh.ang.present;

import com.butuh.uang.tuh.ang.model.YinSiResult;
import com.butuh.uang.tuh.ang.net.Api;
import com.butuh.uang.tuh.ang.ui.FAQActivity;
import com.butuh.uang.tuh.ang.ui.YinSiActivity;
import com.butuh.uang.tuh.ang.util.JsonUtils;

import java.util.HashMap;

import cn.droidlover.xdroidmvp.log.XLog;
import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;
import okhttp3.RequestBody;

public class PFAQ extends XPresent<FAQActivity> {

    public void getFAQ() {
        HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("938", "2");
        paramsMap.put("939", "964");
        paramsMap.put("940", "faq");
        RequestBody body = JsonUtils.mapToBody(paramsMap);
        Api.getNetService().getYinSi(JsonUtils.getAllParmarts(getV()), body)
                .compose(XApi.<YinSiResult>getApiTransformer())
                .compose(XApi.<YinSiResult>getScheduler())
                .compose(getV().<YinSiResult>bindToLifecycle())
                .subscribe(new ApiSubscriber<YinSiResult>() {
                    @Override
                    public void onNext(YinSiResult stBean) {
                        if(null!=stBean.getBody()){
                            if(null!=stBean.getBody().getDatum()){
                                if(stBean.getBody().getDatum().size()!=0){
                                    getV().loadSuccess(stBean.getBody().getDatum().get(0).getDetails());
                                }else{
                                    getV().loadSuccess("");
                                }
                            }else{
                                getV().loadSuccess("");
                            }
                        }else{
                            getV().loadSuccess("");
                        }
                    }

                    @Override
                    protected void onFail(NetError error) {
                        XLog.e("========" + error.getType() + "=====" + error.getMessage());
                        getV().loadError(error.getType(),error.getMessage());

                    }
                });
    }


}
